#ifndef __MYVECTOR
#define __MYVECTOR

namespace MyVector
{

	//tablica bitow, dziala jak wektor, ale zajume malo pamieci
	struct bitCode
	{
		unsigned long long s:6 , value:58;
		bitCode() : s(0) , value(0) {}
		inline void push_back(int b)
		{
	#ifdef __DEBUG
			if (s==58)
				throw "za duzy rozmiar kodu";
	#endif
			value|=(((unsigned long long)b)<<s);
			++s;
		}
		inline void pop_back()
		{
	#ifdef __DEBUG
			if (s==0)
				throw "bitCode pop_back(): wektor pusty";
	#endif
			--s;
			value&=~(1ULL<<s);
		}
		inline int operator[](int i) const
		{
	#ifdef __DEBUG 
			if (i>=s)
				throw "bitCode operator[]: bledny adres";
	#endif
			return (value>>i)&1;
		}
		inline unsigned int size() const
		{
			return s;
		}
		inline void clear()
		{
			s=0,value=0;
		}
	};

	class bitVector
	{
	public:
		int s;
		int maxsize;
		unsigned int *t;
	private:
		inline void sizeCheck()
		{
			if ((s>>5)>=3*(maxsize>>2))
			{
				maxsize<<=1;
				unsigned int *t2 = new unsigned int [maxsize];
				memcpy(t2,t,(s>>5)*sizeof(unsigned int));
				delete[] t;
				t=t2;
			}
		}
		inline void addBit(int bit)
		{
			if ((s&31)==0)
			{
				sizeCheck();
				t[s>>5]=0;
			}
			t[s>>5]|=(((unsigned int)bit)<<(s&31));
			++s;
		}
	public:
		bitVector() : s(0) , maxsize(4) { t = new unsigned int[4];}
		bitVector(const bitVector &bV) : s(bV.s) , maxsize(bV.maxsize)
		{
			t = new unsigned int[maxsize];
			memcpy(t,bV.t,s*sizeof(unsigned int));
		}
		bitVector& operator=(const bitVector &bV)
		{
			delete[] t;
			s=bV.s;
			maxsize=bV.maxsize;
			t = new unsigned int[maxsize];
			memcpy(t,bV.t,s*sizeof(unsigned int));
			return *this;
		}
		inline void push_back(int bit)
		{
			addBit(bit);
		}
		char operator[](int i) const
		{
			return (t[i>>5]>>(i&31))&1;
		}
		inline unsigned size() const
		{
			return s;
		}
	};


	template<class ValueType,class KeyType=unsigned int>
	class myMap
	{
	public:
		vector<KeyType> keys;
		ValueType *values;
		myMap() : values(0) {}
		~myMap()
		{
			if (values)
				delete[] values;
		}
		inline void insert(KeyType key)
		{
			keys.push_back(key);
		}
		ValueType* find(KeyType key)
		{
			vector<KeyType>::iterator it=std::lower_bound(keys.begin(),keys.end(),key);
			if (it!=keys.end() && *it==key)
				return &values[it-keys.begin()];
			return NULL;
		}
		inline const ValueType& operator[](KeyType key) const
		{
			return *find(key);
		}
		inline ValueType& operator[](KeyType key) 
		{
			return *find(key);
		}
		void finalize(const ValueType &v)
		{
			int size=keys.size();
			values = new ValueType[size];
			for (unsigned i=0;i<keys.size();++i)
				values[i]=v;

		}
		inline unsigned size() const
		{
			return keys.size();
		}


	};


	struct PostingItem
	{
		int Title;
		int WordPos;
		long long HashedWord;
		PostingItem(int title,int wordpos,long long hashedword) : Title(title) , WordPos(wordpos) , HashedWord(hashedword) {}
	};

	typedef vector<PostingItem> postingList;

	/*class postingList : public vector<pair<int,int> >
	{
	};*/

}


#endif